using System.Web;
using LinkPointTransaction;
using System.Text;
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
using System.Configuration;
using SiteManager;
using System.Data.SqlClient;

public partial class Dentist_DentistGroupPracticestatus : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        Hashtable dent = new Hashtable();
        dent = (Hashtable)Session["SubscribedDentist"];

        //      Response.Write("<BR>On DoctorGroupPractice Page:<BR>" + Session["SubscribedDoctors"]);

        //      Response.Write("<BR>Doc hashtable count: " + doc.Count + "<BR>");

        //   try
        //   {
        int i;

        //foreach (string strkey in doc.Keys)
        //{
        //    string valuehere = doc[strkey].ToString();
        // //   strjoin2 += valuehere;
        //    Response.Write(valuehere + "<BR>");
        //} 

        Manager mgr = new Manager(true,"ConnectionString");

        HttpBrowserCapabilities bc = Request.Browser;
        fIE5 = (bc.Browser == "IE" && bc.MajorVersion > 4);

        order = (string)Session["outXml"];
        resp = (string)Session["resp"];
        ParseResponse(resp);
        if (R_Approved == "APPROVED")
        {

            lblMsg.Text = "Your Transaction is Been Approved.";
            lblMsg.ForeColor = System.Drawing.Color.Red;
            lblMsg.Font.Bold = true;
            lblMsg.Font.Size = 10;

            clsDentist ObjDentist = new clsDentist();

            for (i = 1; i <= dent.Count; i++)
            {
                ObjDentist = (clsDentist)dent["Dent" + i];
                //           Response.Write("<BR>" + objdoctor.DoctorId + "<br>value of i: " + i);

                ObjDentist.TransactionId = R_Ref;
                ObjDentist.TransactionDate = R_Time;
                ObjDentist.SubscriptionId = R_OrderNum;

                ObjDentist.InsertDentistSubscription();
                mgr.ExecuteScalarQuery("update tbl_Dentists set FeatureDocTypeId ='" + ObjDentist.FeaturedocTypeId + "' where id ='" + ObjDentist.DentistId + "'");

                ObjDentist = null;
            }

        }
        else
        {
            lblMsg.Text = R_Error;
        }

        //   Doctor objdoctor = new Doctor();

        //       for (i = 1; i <= doc.Count; i++)
        //       {
        //           objdoctor = (Doctor)doc["Doc" + i]; 
        //           Response.Write("<BR>" + objdoctor.DoctorId + "<br>value of i: " + i);

        //           objdoctor.TransactionId = "010101";// R_Ref;
        //           objdoctor.TransactionDate = "01/01/2008";// R_Time;
        //           objdoctor.SubscriptionId = "111";//R_OrderNum;

        //           objdoctor.InsertDoctorSubscription();

        //           objdoctor = null;
        //           //Response.Write(doc["drId" + i.ToString()].ToString() + "<BR>");
        //           //Response.Write(doc["DocPhoto" + i.ToString()].ToString() + "<BR>");
        //           //Response.Write(doc["DocEmail" + i.ToString()].ToString() + "<BR>");
        //           //Response.Write(doc["DocStatement" + i.ToString()].ToString() + "<BR>");
        //           //Response.Write(doc["DocWebsite" + i.ToString()].ToString() + "<BR>");
        //           //Response.Write("iD: " + Session["DocId" + i] + " Photo: " + Session["DocPhoto" + i] + " Email: " + Session["DocEmail" + i] + " Statement: " + Session["DocStatement" + i] + " Website: " + Session["DocWebsite" + i]);
        //       }
        ////   }
        ////   catch
        ////   {
        ////       Response.Write("Error Occured");
        ////   }

        //   //// Put user code to initialize the page here
        //   //Manager mgr = new Manager(true,"ConnectionString");

        //   //HttpBrowserCapabilities bc = Request.Browser;
        //   //fIE5 = (bc.Browser == "IE" && bc.MajorVersion > 4);

        //   //order = (string)Session["outXml"];
        //   //resp = (string)Session["resp"];
        //   //ParseResponse(resp);
        //   //if (R_Approved == "APPROVED")
        //   //{

        //   //    string delSql = "delete from doctorsubscription where DoctorId=" + Session["userID"];
        //   //    mgr.ExecuteScalarQuery(delSql);

        //   //    lblMsg.Text = "Your Transaction is Approved.";
        //   //    lblMsg.ForeColor = System.Drawing.Color.Red;
        //   //    lblMsg.Font.Bold = true;
        //   //    lblMsg.Font.Size = 10;
        //   //}
        //   //else
        //   //{
        //   //    lblMsg.Text = R_Error;
        //   //}
    }
    protected void ParseResponse(string rsp)
    {
        R_Time = ParseTag("r_time", rsp);
        R_Ref = ParseTag("r_ref", rsp);
        R_Approved = ParseTag("r_approved", rsp);
        R_Code = ParseTag("r_code", rsp);
        R_Authresr = ParseTag("r_authresronse", rsp);
        R_Error = ParseTag("r_error", rsp);
        R_OrderNum = ParseTag("r_ordernum", rsp);
        R_Message = ParseTag("r_message", rsp);
        R_Score = ParseTag("r_score", rsp);
        R_TDate = ParseTag("r_tdate", rsp);
        R_AVS = ParseTag("r_avs", rsp);
        R_Tax = ParseTag("r_tax", rsp);
        R_Shipping = ParseTag("r_shipping", rsp);
        R_FraudCode = ParseTag("r_fraudCode", rsp);
        R_ESD = ParseTag("esd", rsp);
    }
    protected string ParseTag(string tag, string rsp)
    {
        StringBuilder sb = new StringBuilder(256);
        sb.AppendFormat("<{0}>", tag);
        int len = sb.Length;
        int idxSt = -1, idxEnd = -1;
        if (-1 == (idxSt = rsp.IndexOf(sb.ToString())))
        { return ""; }
        idxSt += len;
        sb.Remove(0, len);
        sb.AppendFormat("</{0}>", tag);
        if (-1 == (idxEnd = rsp.IndexOf(sb.ToString(), idxSt)))
        { return ""; }
        return rsp.Substring(idxSt, idxEnd - idxSt);
    }
    protected LinkPointTxn LPTxn;
    protected string order;
    protected string resp;
    protected bool fIE5;
    protected string R_Time;
    protected string R_Ref;
    protected string R_Approved;
    protected string R_Code;
    protected string R_Authresr;
    protected string R_Error;
    protected string R_OrderNum;
    protected string R_Message;
    protected string R_Score;
    protected string R_TDate;
    protected string R_AVS;
    protected string R_FraudCode;
    protected string R_ESD;
    protected string R_Tax;
    protected string R_Shipping;
}
